home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE03
/
TIPTRIX
/
POPUPSU.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1995-07-18
|
2KB
|
87 lines
unit Popupsu;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Menus, StdCtrls, ExtCtrls, Grids, Outline;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Button1: TButton;
PopupMenu1: TPopupMenu;
DummyItem: TMenuItem;
Memo1: TMemo;
ListBox1: TListBox;
RadioButton1: TRadioButton;
Notebook1: TNotebook;
Outline1: TOutline;
N1: TMenuItem;
Menuitem1: TMenuItem;
Menuitem2: TMenuItem;
Menuitem3: TMenuItem;
EtcItem: TMenuItem;
procedure PopupMenu1Popup(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
function FindComponentAtCursor: TWinControl;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.FindComponentAtCursor: TWinControl;
var
Pt: TPoint;
begin
GetCursorPos(Pt);
Result := FindControl(WindowFromPoint(Pt));
end;
procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
with PopupMenu1 do
begin
PopupComponent := FindComponentAtCursor;
{ Write to the menu first, to make sure it is brought into life }
{ If you do this last, the EnableMenuItem call will have had no }
{ effect, since the menu won't actually exist }
if PopupComponent <> nil then
DummyItem.Caption := PopupComponent.Name + ': ' + PopupComponent.ClassName;
{ No component of ours under cursor so get rid of menu item ... }
DummyItem.Visible := PopupComponent <> nil;
{ ... and seperator }
N1.Visible := PopupComponent <> nil;
{ Disable the dummy menu item, but _don't_ grey it out }
{ The Enabled property does grey the menu item when set to False }
EnableMenuItem(Handle, DummyItem.Command,
mf_ByCommand or mf_Disabled);
end;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Pt: TPoint;
begin
GetCursorPos(Pt);
if (ssAlt in Shift) and (Key = vk_F10) then
PopupMenu1.Popup(Pt.X, Pt.Y);
end;
end.